package com.marry.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @path：com.marry.business.config.SwaggerConfig.java
 * @className：SwaggerConfig.java
 * @description：Swagger配置类
 * @author：LiuYun
 * @dateTime：2021/7/3 18:22
 * @editNote：
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebFluxConfigurer {

    @Bean
    public Docket api() {
//        List<RequestParameter> globalRequestParameters = new ArrayList<>();
//        RequestParameter build = new RequestParameterBuilder().name("abc").description("添加swagger公共请求参数abc").required(true).build();
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.marry.*.controller"))
                .paths(PathSelectors.any())
                .build()
//                .globalRequestParameters(globalRequestParameters)
//                .securitySchemes(securitySchemes()) //添加token
//                .securityContexts(securityContexts()) //swagger配置页面访问是否需要传token
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("title")
                .description("swagger文档注释")
                .termsOfServiceUrl("服务地址")
                //.contact(new Contact("content", "其它文档url", "邮箱"))
                .version("1.0")
                .build();

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //swagger-ui的静态资源
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
}
